from scapy.all import ARP, Ether, srp
import sys

def arp_scan(ip_range):
    # Create ARP request packet
    arp_request = Ether(dst="ff:ff:ff:ff:ff:ff") / ARP(pdst=ip_range)
    # Send ARP request and wait for responses
    result = srp(arp_request, timeout=3, verbose=False)[0]
    
    # Extract device information from responses
    devices = []
    for sent, received in result:
        devices.append({"ip": received.psrc, "mac": received.hwsrc})
    
    return devices

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Usage: python3 Arp_scanning.py <ip_range>")
        sys.exit(1)

    ip_range = sys.argv[1]
    print("Scanning the local network...")
    devices = arp_scan(ip_range)
    
    # Print scanned device information
    print("Scan results:")
    for device in devices:
        print(f"IP: {device['ip']}\tMAC: {device['mac']}")
# pip install scapy
# sansjtw